package com.wz.compilerManual.tree;

import com.wz.compilerManual.Production;
import com.wz.compilerManual.Symbol;
import com.wz.compilerManual.add.symbol.*;

public class PredicateTable {

    public static ProductionFormula getProductionFormula(Symbol symbol, String str){
        if (symbol instanceof S_E && new S_number().match(str)){
            return getE_n_formula();
        }
        if (symbol instanceof S_Ee && new S_plus().match(str)){
            return getEe_plus_formula();
        }
        if (symbol instanceof S_Ee && new S_epsilon().match(str)){
            return getEe_epsilon_formula();
        }
        if (symbol instanceof S_N && new S_number().match(str)){
            return getN_n_formula();
        }
        if (symbol instanceof S_Nn && new S_number().match(str)){
            return getNn_number_formula();
        }
        if (symbol instanceof S_Nn && new S_plus().match(str)){
            return getNn_plus_formula();
        }
        if (symbol instanceof S_Nn && new S_epsilon().match(str)){
            return getNn_doller_formula();
        }
        return getNull_formula();
    }

    private static ProductionFormula getE_n_formula(){
        Symbol[] right = new Symbol[2];
        right[0] = new S_Ee();
        right[1] = new S_N();

        return new ProductionFormula(new S_E(),right);
    }

    private static ProductionFormula getEe_plus_formula(){
        Symbol[] right = new Symbol[3];
        right[0] = new S_Ee();
        right[1] = new S_N();
        right[2] = new S_plus();

        return new ProductionFormula(new S_Ee(),right);
    }

    private static ProductionFormula getEe_epsilon_formula(){
        Symbol[] right = new Symbol[1];
        right[0] = new S_epsilon();

        return new ProductionFormula(new S_Ee(),right);
    }

    private static ProductionFormula getN_n_formula(){
        Symbol[] right = new Symbol[2];
        right[0] = new S_Nn();
        right[1] = new S_number();

        return new ProductionFormula(new S_N(),right);
    }

    private static ProductionFormula getNn_number_formula(){
        Symbol[] right = new Symbol[2];
        right[0] = new S_Nn();
        right[1] = new S_number();

        return new ProductionFormula(new S_Nn(),right);
    }

    private static ProductionFormula getNn_plus_formula(){
        Symbol[] right = new Symbol[1];
        right[0] = new S_epsilon();

        return new ProductionFormula(new S_Nn(),right);
    }

    private static ProductionFormula getNn_doller_formula(){
        Symbol[] right = new Symbol[1];
        right[0] = new S_epsilon();

        return new ProductionFormula(new S_Nn(),right);
    }

    private static ProductionFormula getNull_formula(){
        return null;
    }
}